import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Index',
    component: () => import('../views/layout/Index.vue'),
    meta: {
      title: '项目看板' // 设置浏览器标题为"首页"
    },
    children: [{
      path: '/dashboard',
      name: 'Dashboard',
      component: () => import('../views/DashBoard.vue'),
      meta: {
        title: '项目看板'
      }
    },
    {
      path: '/detail',
      name: 'Detail',
      component: () => import('../views/Detail.vue'),
      meta: {
        title: '项目详情'
      }
    }
    ]
  },
  {
    path: '/home',
    redirect: '/',
    component: () => import('../views/layout/Index.vue'),
    meta: {
      title: '项目看板' // 设置浏览器标题为"首页"
    }
  },
  {
    path: '/404',
    name: 'NotFound',
    component: () => import('../views/NotFound.vue'),
    meta: {
      title: '不存在页面'
    }
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach(async (to) => {
  if (to.meta.title) { // 判断是否有标题
    document.title = to.meta.title
  }
})

export default router
